import { defHttp } from '@/utils/http/axios'
import type { ChangePwdReq, EmployeeInfoResp, LoginReq, LoginResp } from '@/model/sys/indexModel'
import type { ErrorMessageMode } from '@/types/axios'

enum Api {
  Login = '/login',
  Logout = '/logout',
  Info = '/info',
  ChangePwd = '/change-pwd',
}

export const indexApi = {
  login(params: LoginReq, mode: ErrorMessageMode = 'modal') {
    return defHttp.post<LoginResp>({ url: Api.Login, params }, { errorMessageMode: mode })
  },
  logout() {
    return defHttp.post({ url: Api.Logout })
  },
  info() {
    return defHttp.get<EmployeeInfoResp>({ url: Api.Info })
  },
  changePwd(params: ChangePwdReq) {
    return defHttp.post({ url: Api.ChangePwd, params })
  },
}

// 登出
export function logout() {
  return defHttp.post({ url: Api.Logout })
}
